/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Exercicio3;

import java.util.HashMap;
import java.util.Stack;

/**
 *
 * @author Pedro-Note
 */
public class Principal {

   Principal(){

    }

    public static void main(String[] args)
    {

        Stack<HashMap<String,Double>> pilha = new Stack<HashMap<String,Double>>();
        Stack<Double> pilhaResultado = new Stack<Double>();
        
        HashMap integral = new HashMap();
        integral.put("left", 10.0);
        integral.put("right", 20.0);
        integral.put("fleft", 30.0);
        integral.put("fright", 40.0);
        integral.put("lrarea", 50.0);
        pilha.push(integral);
        
        int P = 4;
        ThreadCalculaIntegral [] thread = new ThreadCalculaIntegral[P];
        
        for(int i = 0; i < P; i++)
        {
          thread[i] = new ThreadCalculaIntegral(pilha, pilhaResultado);
          thread[i].start();
        }
        
        int inativos = 0;
        int i = 0;
        
        while(inativos < P)
        {
           if (!thread[i%P].isAlive())
               inativos++;
           else if(inativos > 0)
               inativos--;

           i++;
        }
        
        System.out.println("Resultado:" + pilhaResultado.pop());



    }

}
